var win;
Ext.onReady(function() {
	/**
	 * 修改密码面板
	 */
	var changPasswordPanel = new Ext.FormPanel({
				labelWidth : '50%',
				id : 'changPasswordPanel',
				frame : true,
				bodyStyle : 'padding:5px 5px 0',
				monitorValid : true,
				layout : 'form',
				width : '270',
				height : '200',
				columnWidth : 1,
				items : [{
							layout : 'form',
							columnWidth : 1,
							items : [{
										xtype : 'textfield',
										anchor : '90%',
										fieldLabel : '用户名',
										name : 'user_name',
										id : 'user_name',
										allowBlank : false,
										blankText : '用户名必填',
										readOnly : true,
										emptyText : '请输入用户名'
									}, {
										xtype : 'textfield',
										anchor : '90%',
										inputType : "password",
										fieldLabel : '密码',
										name : 'pwd',
										id : 'pwd',
										allowBlank : false
									}, {
										xtype : 'textfield',
										anchor : '90%',
										fieldLabel : '新密码',
										inputType : "password",
										name : 'newpwd',
										id : 'newpwd',
										allowBlank : false
									}, {
										xtype : 'textfield',
										anchor : '90%',
										fieldLabel : '确认新密码',
										inputType : "password",
										name : 'newpwdagin',
										id : 'newpwdagin',
										allowBlank : false
									}]
						}]
			});
	win = new Ext.Window({
		layout : 'form',
		resizable : false,
		modal : 'true',
		monitorValid : true,
		closable : false,
		closeAction : 'hide',
		draggable : false,
		title : '修改密码',
		width : 280,
		plain : true,
		items : [changPasswordPanel],
		listeners : {
			"beforedestroy" : function(obj) {
				return true;
			},
			"beforeshow" : function(obj) {
				return true;
			},
			"beforehide" : function(obj) {
				changPasswordPanel.form.reset();
				return true;
			}
		},
		buttons : [{
			text : '确定',
			id : 'frm_submit',
			formBind : true,
			type : 'submit',
			handler : function() {
				if (changPasswordPanel.form.isValid()) {
					var pwd = document.getElementById("pwd").value;
					var newPwd1 = document.getElementById("newpwd").value;
					var newPwd2 = document.getElementById("newpwdagin").value;
					if (newPwd1 != newPwd2) {
						Ext.Msg.alert("警告", "两次输入的密码不一样，请重新输入！");
						changPasswordPanel.form.reset();
						document.getElementById("user_name").value = userName;
						return;
					}else if(newPwd1==pwd){
						Ext.Msg.alert("警告", "设置的新密码不能等于输入的原密码，请重新输入！");
						changPasswordPanel.form.reset();
						document.getElementById("user_name").value = userName;
						return;
					}

					Ext.Ajax.request({
						url : 'ChangePwd!changPwd.action',
						params : {
							user_name : document.getElementById("user_name").value,
							pwd : document.getElementById("pwd").value,
							newpwd : document.getElementById("newpwd").value
						},
						success : function(result, request) {
							var failstr = Ext.util.JSON
									.decode(result.responseText);
							if (failstr.resultString != "") {
								Ext.Msg.alert('提示信息', failstr.resultString);
								changPasswordPanel.form.reset();
								document.getElementById("user_name").value = userName;
							} else {
								Ext.Msg.alert('提示信息', '密码修改成功');
								win.hide();
							}
						},
						failbure : function(result, request) {
							var failstr = Ext.decode(result.responseText);
							Ext.Msg.show({
										title : '提示信息',
										msg : '密码修改失败，可请确认原密码输入正确！',
										buttons : Ext.Msg.OK
									});
						}
					});

				}
			}
		}, {
			text : '重置',
			handler : function() {
				changPasswordPanel.form.reset();
				document.getElementById("user_name").value = userName;
			}
		}, {
			text : '关闭',
			id : 'winclose',
			handler : function() {
				win.hide();
			}
		}]
	});
	if (userStatus == "20") {
		alert("由于长时间没有修改密码，请现在修改密码！");
		win.show();
		Ext.getCmp('winclose').hide();
		document.getElementById("user_name").value = userName;
	} else if (userStatus == "10") {
		alert("您有一段时间没有修改密码了，请尽快进入修改页面修改密码！");
	}
});
function changpassword() {
	win.show();
	document.getElementById("user_name").value = userName;
}